/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl_cmts;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

/**
 *
 * @author Kojino
 */
public class N_gram {
    HashMap<String, word> hmap1 = new HashMap<String, word>();
    public ArrayList<String> ngrams(int n, String str) {
        ArrayList<String> ngrams = new ArrayList<String>();
        str = str.toLowerCase();
        String[] words = str.split(" ");
        for (int i = 0; i < words.length - n + 1; i++)
            ngrams.add(concat(words, i, i+n));
        return ngrams;
    }

    public static String concat(String[] words, int start, int end) {
        StringBuilder sb = new StringBuilder();
        for (int i = start; i < end; i++)
            sb.append(i > start ? " " : "").append(words[i]);
        return sb.toString();
    }
	
    public HashMap<String, word> them_tu(ArrayList<String> dsTu, HashMap<String,word> hmap){
        for(String tu : dsTu){
            if(hmap.containsKey(tu)){
                int solan = hmap.get(tu).getSolan();
                hmap.get(tu).setSolan(solan+1);
            } 
            else{
                word w = new word(tu, 1);
                hmap.put(tu, w);
            }
        }
        return hmap;
    }  
}
